<!--
 * @Author: Freude Xu
 * @Date: 2021-10-05 17:29:14
 * @LastEditors: Freude Xu
 * @LastEditTime: 2021-10-05 17:35:45
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件代理</title>
</head>

<body>
    <ul>
        <li>你好</li>
        <li>你好</li>
        <li>你好</li>
        <li>你好</li>
        <li>你好</li>
    </ul>
</body>
<script>
    //事件委托的原理：不是给每个子节点单独设置事件监听器，而是事件监听器设置再其父节点上，然后利用冒泡原理影响设置每个子节点
    var ul = document.querySelector('ul');
    ul.addEventListener('click', function(e) {
        alert('你好');
        //e.target这个可以得到我们点击的对象
        e.target.style.backgroundColor = 'pink';
    })
</script>

</html>